#include <stdio.h>
#include <SDL.h>
#include <SDL_image.h>

int main0(int argc, char *argv[])
{
    //窗口含有的surface
    SDL_Surface* screenSurface = NULL;

    //初始化SDL
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
    }
    else {
        //创建 window
        SDL_Window *window = SDL_CreateWindow("ShowPicture", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
        if (window == NULL)
        {
            printf("Window could not be created! SDL_Error: %s\n", SDL_GetError());
        }
        else {
            //渲染层
            SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, 0);
            SDL_Surface *pic = SDL_LoadBMP("sdl_test.bmp");
            //载入的图片生成SDL材质
            SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, pic);

            //把材质复制到渲染器
            SDL_RenderCopy(renderer, texture, NULL, NULL);
            //显示出来
            SDL_RenderPresent(renderer);

            int quit = 0;
            SDL_Event event;

            while (!quit)
            {//主消息循环
                SDL_WaitEvent(&event);

                switch (event.type)
                {
                    //用户从菜单要求退出程序
                    case SDL_QUIT:
                        quit = 1;
                        break;
                }
            }

            // 清理资源
            SDL_DestroyTexture(texture);
            SDL_FreeSurface(pic);
            SDL_DestroyRenderer(renderer);
            SDL_DestroyWindow(window);
        }
    }

    //退出SDL
    SDL_Quit();

    return 0;
}